# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=cargo-pgx
pkgver=0.7.1
pkgrel=1
pkgdesc='Build PostgreSQL extensions with Rust'
arch=('loong64' 'x86_64')
url='https://github.com/tcdi/pgx'
license=('MIT')
depends=('gcc-libs' 'openssl' 'clang' 'llvm' 'bzip2')
optdepends=(
  'postgresql: to compile with system postgresql'
)
makedepends=('git' 'rust')
options=('!lto')
_commit='4b9467aebfd88c71cf0531b76cb524350ef0b698'
source=("$pkgname::git+$url.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # download dependencies
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "$pkgname"

  cargo build --release --frozen --package cargo-pgx
}

package() {
  cd "$pkgname"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" "target/release/$pkgname"

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
